package bim.web.controller;

import javax.validation.Validator;

import keter.web.controller.KeterBaseController;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;

import bim.dao.UserDao;
import bim.domain.User;

@Controller
public class BaseController extends KeterBaseController {
    
    @Autowired
    protected Validator validator;

    @Autowired
    UserDao dao;
    
    private static final Logger logger = LoggerFactory.getLogger(BaseController.class);

    public BaseController() {
      
    }

	/**
	 * <p>Method ：populateCurrentUser
	 * <p>Description : 将当前用户放入JSTL全局变量
	 * @return 
	 * @author  gulixing@msn.com
	 * @version 1.0.0
	 */
	@ModelAttribute("user")
	public User populateCurrentUser() {
		return getCurrentUser();
	}

	public User getCurrentUser() {
        if(!isLoggedIn()){
            return null;
        }
        return dao.findByAccount(getCurrentAccount());    
    }
    
}